package cn.alusiaor.commonutil;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * @Author: zhuzhiping
 * @Description: 日期
 * @Date: 2020/10/21 13:56
 */

public class DateUtil {

    /**
     * Date 转   LocDateTime
     */

    public static LocalDateTime DateToLocalDateTime(Date date) {
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        return localDateTime;
    }

    /**
     * 日期间隔
     */
    public static long daysBetweenDates(LocalDate localDate1, LocalDate localDate2) {
        return Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2));
    }

    /**
     * 日期前后
     */
    public static int position(LocalDate var1, LocalDate var2) {
        if (var1.isAfter(var2)) {
            return -1;
        } else if (var1.isBefore(var2)) {
            return 1;
        } else {
            return 0;
        }
    }


    /**
     * LocalDateTime日期格式化
     */
    public static String dateFormat(LocalDateTime var1, String dateTimeFormatOfPattern) {
        String format = DateTimeFormatter.ofPattern(dateTimeFormatOfPattern).format(var1);
        return format;
    }

    /**
     * LocalDate转 LocalDateTime
     */
    public static LocalDateTime localDate转ToLocalDateTime(LocalDate localDate) {
        return LocalDateTime.now();
    }


    /**
     * LocalDateTime 转   LocalDate
     */

    /**
     * 时间戳转 LocalDateTime
     */


    /**
     * LocalDateTime  转   时间戳
     */


    /**
     * 日期字符串  转   LocalDateTime
     */

}
